package chapter3;
import java.util.Scanner;
/****************************************************************
 * Author：icynlau
 * Description:  第二个矩形是在第一个矩形内/外/重叠
 * 			我的思路是比较矩形中心间距 和 矩形的长宽
 * Date:2021/4/1
 * Others:
 * 测试时发现，课本中给的第一个运行示例是矩形2与矩形1边重叠，而我把这种情况当作overlap了，所以检查了好几次bug在哪
Enter r1's center x- y-coordinates,width,and height: 
2.5 4 2.5 43
Enter r2's center x- y-coordinates,width,and height: 
1.5 5 0.5 3
r2 is inside r1.    
 * ***************************************************************
 */
public class exc3_28 {
	

	
	public static void main(String[] args) {
		Scanner input=new Scanner(System.in);
		System.out.println("Enter r1's center x- y-coordinates,"
				+ "width,and height: ");
		double x1=input.nextDouble();
		double y1=input.nextDouble();
		double w1=input.nextDouble();
		double h1=input.nextDouble();
		System.out.println("Enter r2's center x- y-coordinates,"
				+ "width,and height: ");
		double x2=input.nextDouble();
		double y2=input.nextDouble();
		double w2=input.nextDouble();
		double h2=input.nextDouble();
		
		
		
		if( (w2/2+Math.abs(x2-x1))<=w1/2 && (h2/2+Math.abs(y2-y1))<=h1/2) {
			
			System.out.println("r2 is inside r1.");  //注意条件中的=等号不要丢，要不然这类测试数据都会被当成overlap
			
		}else if(Math.abs(x2-x1)-w2/2>w1/2 && Math.abs(y2-y1)-h2/2>h1/2 ) {
			System.out.println("r2 does not overlap r1.");
			
		}else {
			System.out.println("r2 overlaps r1.");
		}
		
	}
	
	

}
